﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="BalanceManage.aspx.cs" Inherits="MobileServer.Web.Admin.BalanceManage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
        EnableModelValidation="True" Height="50px" Width="125px">
        <Fields>
            <asp:TemplateField HeaderText="ActivityId" SortExpression="ActivityId">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ActivityId") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
                        DataSourceID="SqlDataSource2" DataTextField="Title" DataValueField="ID" 
                        SelectedValue='<%# Bind("ActivityId") %>'>
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ActivityId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="UserID" SortExpression="UserID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserID") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" 
                        DataSourceID="SqlDataSource3" DataTextField="Name" DataValueField="Id" 
                        SelectedValue='<%# Bind("UserID") %>' AppendDataBoundItems="True">
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("UserID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Amount" HeaderText="Amount" 
                SortExpression="Amount" />
            <asp:TemplateField HeaderText="Type" SortExpression="Type">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Type") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" 
                        SelectedValue='<%# Bind("Type") %>'>
                        <asp:ListItem Value="0">支出</asp:ListItem>
                        <asp:ListItem Value="5">补贴</asp:ListItem>
                        <asp:ListItem Value="9">会费</asp:ListItem>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Type") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="Id" DataSourceID="SqlDataSource1" EnableModelValidation="True">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" 
                SortExpression="Id" />
            <asp:TemplateField HeaderText="ActivityId" SortExpression="ActivityId">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
                        DataSourceID="SqlDataSource2" DataTextField="Title" DataValueField="ID" 
                        SelectedValue='<%# Bind("ActivityId", "{0}") %>'>
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="UserID" SortExpression="UserID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" 
                        DataSourceID="SqlDataSource3" DataTextField="Name" DataValueField="Id" 
                        SelectedValue='<%# Bind("UserID") %>' AppendDataBoundItems="True">
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Amount" HeaderText="Amount" 
                SortExpression="Amount" />
            <asp:TemplateField HeaderText="Type" SortExpression="Type">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" 
                        SelectedValue='<%# Bind("Type") %>'>
                        <asp:ListItem Value="0">支出</asp:ListItem>
                        <asp:ListItem Value="5">补贴</asp:ListItem>
                        <asp:ListItem Value="9">会费</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# ((int)Eval("Type")) == 0 ? "支出" : ((int)Eval("Type")) == 5 ? "补贴" : "会费" %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="UpdateTime" HeaderText="UpdateTime" 
                SortExpression="UpdateTime"  ReadOnly="true"/>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DefaultDB %>" 
        DeleteCommand="DELETE FROM [Bis_Balance] WHERE [Id] = @Id" 
        InsertCommand="INSERT INTO [Bis_Balance] ( [ActivityId], [UserID], [Amount], [Type]) VALUES ( @ActivityId, @UserID, @Amount, @Type)" 
        SelectCommand="SELECT *, (select Title from bis_activity where bis_activity.Id=Bis_Balance.ActivityId) as Title, (select [Name] from sec_user where sec_user.Id= Bis_Balance.Userid) as [Name] FROM [Bis_Balance] ORDER BY UpdateTime DESC" 
        UpdateCommand="UPDATE [Bis_Balance] SET [ActivityId] = @ActivityId, [UserID] = @UserID, [Amount] = @Amount, [Type] = @Type WHERE [Id] = @Id">
        <DeleteParameters>
            <asp:Parameter Name="Id" Type="Object" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ActivityId" />
            <asp:Parameter Name="UserID"/>
            <asp:Parameter Name="Amount" Type="Single" />
            <asp:Parameter Name="Type" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ActivityId" />
            <asp:Parameter Name="UserID" />
            <asp:Parameter Name="Amount" Type="Single" />
            <asp:Parameter Name="Type" Type="Int32" />
            <asp:Parameter Name="Id" Type="Object" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DefaultDB %>" 
        SelectCommand="SELECT [ID], [Title] FROM [Bis_Activity] ORDER BY StartDate DESC">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DefaultDB %>" 
        SelectCommand="SELECT [Id], [Name] FROM [SEC_User] ORDER BY [Name]"></asp:SqlDataSource>
</asp:Content>
